package com.xiaoxin_project.netty;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFactory;
import io.netty.channel.ChannelFuture;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import org.springframework.stereotype.Component;

@Component
public class WSServer {
    private static class SingletionWSServer {
        static final WSServer instancea = new WSServer();
    }

    public static WSServer getInstance() {
        return SingletionWSServer.instancea;
    }

    private ServerBootstrap service;
    private ChannelFuture future;

    public WSServer() {
        service = new ServerBootstrap();
        service.group(new NioEventLoopGroup())
                .channel(NioServerSocketChannel.class)
                .childHandler(new WSServerInitializer());
    }

    //开启服务器
    public void start() {
        this.future = service.bind(8088);
        System.err.println("netty启动完毕===");
    }



}
